package xx.pro.producer.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 直连交换机
 */
@Configuration
public class DirectRabbitConfig {
    /**
     * 设置队列名称及相关属性
     * 一般设置一下队列的持久化就好,其余两个就是默认false
     * @return
     */
    @Bean
    public Queue directQueue() {
        return new Queue("direct.queue", true);
    }

    /**
     * Direct交换机
     * @return
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("direct.exchange", true, false);
    }

    /**
     * 绑定  将队列和交换机绑定, 并设置用于匹配键：DIRECT_QUEUE_Exchange_KEY
     * @return
     */
    @Bean
    public Binding bindingDirect() {
        return BindingBuilder.bind(directQueue()).to(directExchange()).with("DIRECT_QUEUE_EXCHANGE_KEY");
    }
}
